package com.glodon.paas.activity.resource.internal;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;

import org.springframework.stereotype.Component;

@Component
@Path("/internal/activityDemo")
public class ActivityDemoInternalResource {

    // http://127.0.0.1:8080/activity/api/internal/activityDemo/demo
    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Path("/demo/{pathParam}")
    public Map<String, Object> getDemo(
              @Context UriInfo uriInfo,
              @Context HttpHeaders httpHeaders,
              @PathParam("pathParam") String pathParam,
              // @QueryParam("queryParam") String queryParam,
              @Context HttpServletRequest request, 
              @Context HttpServletResponse response
              ) {
        Map<String, Object> param = new HashMap<String, Object>();
        MultivaluedMap<String, String> pathParameters = uriInfo.getPathParameters();
        MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
        // param.put("uriInfo", uriInfo);
        // param.put("httpHeaders.getAcceptableLanguages", httpHeaders.getAcceptableLanguages());
        // param.put("httpHeaders.getAcceptableMediaTypes", httpHeaders.getAcceptableMediaTypes());
        // param.put("httpHeaders.getLanguage", httpHeaders.getLanguage());
        // param.put("httpHeaders.getMediaType", httpHeaders.getMediaType());
        // param.put("httpHeaders.getCookies", httpHeaders.getCookies());
        param.put("sessionId", request.getSession() == null ? -1 : request.getSession().getId());
        param.put("pathParam", pathParam);
        param.put("pathParameters", pathParameters);
        param.put("queryParameters", queryParameters);
        // param.put("queryParam", queryParam);

        param.put("version", "activicy-1.0.0 ");
        param.put("submitDate", "2012-12-04");

        return param;
    }
    
    // http://127.0.0.1:8080/activity/api/internal/activityDemo/demo
    @POST
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Path("/demo/{pathParam}")
    public Map<String, Object> postDemo(
              @PathParam("pathParam") String pathParam,
              @QueryParam("queryParam") String queryParam,
              String postParam
              ) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("pathParam", pathParam);
        param.put("queryParam", queryParam);
        param.put("postParam", postParam);

        param.put("version", "activicy-1.0.0 ");
        param.put("submitDate", "2012-12-04");

        return param;
    }
}
